1. Technical Field
The present invention relates generally to computer systems and in particular to memory functions within a computer system. Still more particularly, the present invention relates to a method and system for creating large virtual memory pages from smaller pages in a computer system.
2. Description of the Related Art
Almost all modern operating systems utilize a page-based virtual memory architecture where virtual memory is mapped to real memory in units of pages. The amount of available memory is finite, and the memory is subdivided into multiple individual pages of a pre-established size. To improve system performance, many computer architectures and operating systems have begun adding support for multiple page sizes within a single system.
On systems that support multiple page sizes, an operating system may need to change the distribution of real memory across page sizes to satisfy the demands of a particular workload. In order to create more pages of a particular page size, an operating system must find free (unused) pages of other sizes and convert them into pages of the needed size. For example, on a system with two page sizes of 4K and 64K, respectively, the current workload on the operating system may have more demand for 4K pages than 64K pages. The operating system may thus need to increase the number of 4K pages, and can only do so by decreasing the number of 64K pages (i.e., breaking up one or more of the 64K pages into 4K pages).
When an operating system needs to increase the number of small pages, the operating system can break up a free larger sized page into multiple smaller sized pages (via a process referred to in the art as page demotion). For example, an operating system can break up a free 64K page by simply treating it as 16-4K pages. Thus, increasing the number of smaller sized pages is fairly simple.
However, creating large pages from small pages (a process referred to in the art as page promotion) is much more difficult and presents a significant challenge due to fragmentation. For example, in order to create a 64K page from 4K pages, an operating system must find 16 free 4K pages that are contiguous in real memory and then combine them into a 64K page. On a heavily utilized system, finding sufficient contiguous free small pages to create a large page is often difficult, if not impossible.
To handle fragmentation of small virtual memory pages on a heavily utilized system, an operating system will often use page migration to move small pages around in real memory in order to create a contiguous range of free small pages. For example, if an operating system is trying to free-up 16 contiguous 4K pages to create a 64K page, the operating system could migrate each in-use 4K page in the target range to another location in real memory. Thus, the operating system moves out all of the in-use 4K pages in a contiguous range of real memory, and then the operating system utilizes that contiguous range of real memory as a large page.
While using conventional page migration to free up contiguous ranges of small pages is fairly efficient, the process is often hindered by the presence, within the memory, of pages that are locked (i.e. pinned) and thus not able to be migrated. In addition to the limitations imposed by the occurrence of locked pages, other pages mapped for direct memory access (DMA) cannot be migrated. The conventional page migration engine allows the operating system to efficiently move small pages to different real memory locations. However, a conventional page migration engine cannot handle pinned pages or DMA-mapped pages.
Thus, if a system has many pinned pages and/or many pages mapped for DMA scattered throughout real memory, a conventional page migration engine will be ineffective in migrating these in-use pages to free up enough contiguous small pages for promotion to a larger page. That is, the operating system will not be able to provide enough contiguous small pages to combine into a large virtual memory page. With this restriction, the operating system's ability to dynamically change the distribution of real memory across a system's page sizes is substantially limited. Workload requiring larger pages may encounter serious performance degradation because the operating system is unable to create enough pages of the size needed by the workload.
The present invention recognizes that a method is required to enable dynamic migration of sufficient in-use small pages to generate large pages required for a workload regardless of whether the pages are pinned or mapped to DMA. This and other benefits are provided by the invention described herein.